package com.yanjiali.constant;

/**
 * @Package: com.yanjiali.com.yanjiali.constant
 * @Author: yanjiali
 * @Created: 2025/4/4 17:16
 * 设置登录类型常量
 */
public class LoginConstant {

    /**
     * 管理员登录
     */
    public static final String ADMIN_TYPE = "admin_type";

    /**
     * 普通用户登录
     */
    public static final String MEMBER_TYPE = "member_type";

    /**
     * TODO 普通登录查询用户所有角色的所有权限 ## 都改为我能理解的名字吧
     */
    public static final String MEMBER_TYPE_QUERY_PRIVILEGE =
            "SELECT sp.`name` FROM sys_privilege AS sp INNER JOIN sys_role_privilege AS srp ON sp.id = srp.privilege_id INNER JOIN sys_user_role AS sur ON srp.role_id = sur.role_id AND sur.type = 2 WHERE sur.user_id = ?";

    /**
     * TODO 使用用户名查询用户
     */
    public static final String QUERY_ADMIN_SQL =
            "SELECT `id` ,`username`, `password`, `status` FROM sys_user WHERE username = ?";

    /**
     * TODO 判断用户是否为管理员，改过SQL
     */
    public static final String QUERY_ROLE_CODE_SQL =
            "SELECT `code` FROM sys_role INNER JOIN sys_user_role ON sys_role.id = sys_user_role.role_id WHERE sys_user_role.type = 1 AND sys_user_role.user_id = ? ORDER BY sys_role.priority DESC LIMIT 1;";


    /**
     * TODO 管理员登录类型中的——超级管理员
     */
    public static final String QUERY_ALL_PERMISSIONS =
            "SELECT `name` FROM sys_privilege";

    /**
     * TODO 管理员登录类型中的——普通后台人员
     */
    public static final String QUERY_PERMISSION_SQL =
            "SELECT sp.`name` FROM sys_privilege sp INNER JOIN sys_role_privilege srp ON sp.id = srp.privilege_id INNER JOIN sys_user_role sur ON srp.role_id = sur.role_id AND sur.type = 1 WHERE sur.user_id = ?";

    /**
     * TODO 管理员角色
     */
    public static final String ADMIN_ROLE_CODE = "ROLE_ADMIN";

    /**
     * TODO 会员查询sql——通过手机或邮箱或用户名查询用户信息
     */
    public static final String QUERY_MEMBER_SQL =
            "SELECT `id`,`password`, `status` FROM `user` WHERE phone = ? or email = ? or username = ?";

    /**
     * TODO 用于检验是否通过 REFRESH_TOKEN 获取的token
     */
    public static final String REFRESH_TOKEN = "REFRESH_TOKEN";

    /**
     * TODO 使用用户的 id 查询用户名称
     */
    public static final String QUERY_ADMIN_USER_WITH_ID = "SELECT `username` FROM sys_user where id = ?" ;

    /**
     * TODO 使用用户的 id 查询用户名称，这里普通用户获取到的是电话根据自己的登录修改
     */
    public static final String QUERY_MEMBER_USER_WITH_ID = "SELECT `username` FROM user where id = ?" ;

}
